package com.javasm.service.impl;

import com.javasm.dao.GodUserDao;
import com.javasm.entity.GodUser;
import com.javasm.service.GodUserService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GodUserServiceImpl implements GodUserService {
    public int addGodCustomer(GodUser inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int result = sqlSession.getMapper(GodUserDao.class).addGodCustomer(inputCustomer);
        sqlSession.commit();
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }
    public int countGodCustomers(GodUser inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int result = sqlSession.getMapper(GodUserDao.class).countGodCustomers(inputCustomer);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }

    public int deleteGodCustomerById(Integer customerId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int result = sqlSession.getMapper(GodUserDao.class).deleteGodCustomerById(customerId);
        sqlSession.commit();
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }

    public int editGodCustomer(GodUser inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int result = sqlSession.getMapper(GodUserDao.class).editGodCustomer(inputCustomer);
        sqlSession.commit();
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }

    public GodUser getGodCustomerById(Integer customerId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodUser result = sqlSession.getMapper(GodUserDao.class).getGodCustomerById(customerId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }

    public List<GodUser> listGodCustomers(GodUser inputCustomer, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        List<GodUser> result = sqlSession.getMapper(GodUserDao.class).listGodCustomers(inputCustomer, (page - 1) * pageSize, pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return result;
    }



}
